package com.typhoon.spring_redis.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.typhoon.spring_redis.dto.UserDto;
import com.typhoon.spring_redis.service.UserService;

@Controller
@RequestMapping("user")
public class UserController {
	
	private static final Logger logger = LoggerFactory.getLogger(UserController.class);
	
	@Autowired
	private UserService userService;
	
	@RequestMapping(value = "/get-user")
	@ResponseBody
	public UserDto getUser(HttpServletRequest request,HttpServletResponse response) {
		String id = request.getParameter("id");
		logger.info("id:{}",id);
		if(StringUtils.isEmpty(id))
			return null;
		return userService.queryByPK(Long.valueOf(id));
	}
	
	@RequestMapping(value = "/get-redis")
	@ResponseBody
	public Long getValueFromRedis(HttpServletRequest request,HttpServletResponse response) {
	return 10l;
	}

}
